//
//  globalVariables.cpp
//  learnC++
//
//  Created by apple on 2018/5/23.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#include "globalVariables.hpp"
//通常全局变量以g_开头，避免重名  例如 g_value(5);

int value(5);

int g_y(10);



globalVariables::globalVariables(){
    int value(7);
    value++;
    ::value--;//全局作用域符号：当全局变量在局部函数中与其中某个变量重名，那么就可以用::来区分

    std::cout << "global value: " << ::value << "\n";
    std::cout << "local value: " << value << "\n";
    
    std::cout << "static value: " << g_x << "\n";
    std::cout << "extern value: " << g_y << "\n";
    
    addValue(2, 3);
}

globalVariables::~globalVariables(){
    std::cout<<"析构方法";
}

int
globalVariables::generateID()
{
    static int s_itemID = 0;//该静态变量只会创建一次
    //可以获取该对象创建了多少次
    return s_itemID++; // makes copy of s_itemID, increments the real s_itemID, then returns the value in the copy
}

//static关键字设置为内部链接
static int addValue(int x, int y)
{
    printf("%d",x+y);
    return x + y;
}

void test(){
    printf("test\n");
}

void test2(){
    printf("test2\n");
}
